package reservation;

import jdk.jshell.SourceCodeAnalysis;

import java.util.Scanner;

public class Order {
    public  static void main(String[]args){
        //订单信息
        System.out.println("欢迎使用吃货联盟订餐系统");
        System.out.println("*************************");
        //使用循环来支撑初始化的进行
        Scanner input=new Scanner(System.in);
        //定义数组存放不同的订单信息
        //餐袋 保存数据
        int shoppingCart=4;//购物车
        String[] names=new String[4];//订餐人名称
        String[] dishMeg={"红烧带鱼","鱼香肉丝"};//菜品名称
        int[] foodCount={1,2};//份数
        int[] times =new int[4];//送餐时间
        String[] adresses = {"小鱼路27","大鱼路27"};//送餐地址
        int[] states={1,0};//订单状态；1表示已完成；0表示未完成
        double[] sumPrices=new double[4];//订单总金额


        //菜单
        int  order=3;//菜单
        String [] foodname={"红烧带鱼","鱼香肉丝","时令蔬菜"};//菜单名称
        double[] price ={38,20,10};//单价
        int[] like=new int[4];//点赞数

        //初始化订单信息
        names[0]="张三";
        dishMeg[0]="红烧带鱼";
        times[0]=13;
        foodCount[0]=2;
        adresses[0]="小鱼路27";
        states[0]=1;
        sumPrices[0]=56;//配送费>40免费，否则加3元的配送费

        names[0]="李青";
        dishMeg[0]="鱼香肉丝";
        times[0]=10;
        foodCount[0]=1;
        adresses[0]="大鱼路27";
        states[0]=0;
        sumPrices[0]=26;//配送费>40免费，否则加3元的配送费

     int num=-1;//输入为零时返回点餐系统
      System.out.println("欢迎使用吃货联盟订餐系统");
      System.out.println("*************************");
        //使用循环来支撑初始化的进行

     do {
         System.out.println("1.我要订餐\t2.查看餐袋\t3.签收订单\t4.删除订单\t5.我要点赞\t6.退出系统");
         System.out.println("请选择菜单：");
         int choose = input.nextInt();
         switch (choose) {
             case 1:
                 System.out.println("******我要订餐******");
                 System.out.println("******我要订餐******");
                 //查找购物车是否已满（以订餐人来查询）
                 int seachIndex = -1;//查找空位的下标
                 for (int i = 0; i < names.length; i++) {
                     if (names == null) {
                         //如果有空位，记录空位，直接跳出
                         seachIndex = i;
                         //记录
                         break;
                     }
                     //判断有空位，开始订餐
                     if (seachIndex != -1) {
                         //输入订餐人姓名
                         System.out.println("请输入订餐人姓名：");
                         String name = input.next();
                         //输出菜单
                         System.out.println("序号\t菜品名称\t价格\t点赞");//菜品信息
                         for (int j = 0; j < dishMeg.length; j++) {//点赞数

                             String likes = (like[j] == 0) ? "" : like[j] + "赞";
                             System.out.println((j + 1) + "\t" + dishMeg[j] + "\t" + price[j] + "\t" + like);

                         }
                         System.out.println("请输入菜品编号：");
                         int no = input.nextInt();
                         while (no > 1 || no < dishMeg.length) {
                             System.out.println("没有这个菜品，情绪重新输入！");
                         }
                         //
                         System.out.println("请输入分数：");
                         int number = input.nextInt();
                         System.out.println("请输入送餐时间：");
                         int time = input.nextInt();
                         while (time < 10 || time > 20) {
                             System.out.println("输入错误，请重新输入！");
                         }
                         //地址
                         System.out.println("请输入地址：");
                         String adress = input.next();
                         System.out.println("订单成功！");
                         String dishInfo = dishMeg[no - 1];
                         System.out.println("您的订单是：" + dishMeg[no - 1] + number + "份");
                         System.out.println("送餐时间:" + time + "点");
                         double disprice = price[no - 1] * number;
                         double peisend = (disprice > 50) ? 0 : 6;
                         double sumPrice = disprice + peisend;
                         System.out.println("餐费：" + disprice + "元；配送费：" + peisend + ";总计：" + sumPrice + "元");
                         //添加订单信息
                         names[i] = name;
                         dishMeg[i] = dishInfo;
                         times[i] = time;
                         adresses[i] = adress;
                         sumPrices[i] = sumPrice;

                     } else {
                         System.out.println("购物车已满，不能订餐！");
                     }
                 }

                 break;
             case 2:
                 System.out.println("******查看餐袋******");
                 for (int i = 0; i < names.length; i++) {
                     System.out.println("序号\t订餐人\t订餐菜品\t配送时间\t配送地址\t订餐金额\t订单状态");
                     System.out.println((i + 1) + names[i] + "\t" + dishMeg[i] + "\t" + times[i] + "\t" + adresses + "\t" + sumPrices + "\t" + states);
                     //查找空值。并输出
                     if (names[i] != null) {
                         String time = times[i] + "点";
                         String state = (states[i] == 0) ? "已预定" : "已完成";

                     }
                 }
                 break;
             case 3:
                 System.out.println("******签收订单******");
                 boolean isSing = false;
                 System.out.println("请输入要签收的编号：");
                 int isNo = input.nextInt();
                 for (int i = 0; i < names.length; i++) {
                     if (names[i] != null && states[i] == 1 && i == (isNo - 1)) {
                         isSing = true;
                         states[i] = 1;
                         System.out.println("订单签收成功！");

                     } else if (names[i] != null && states[i] == 1 && i == (isNo - 1)) {
                         isSing = true;
                         System.out.println("您选择的订单已经完成签收，不能再次签收！");
                     }
                 }
                 if (!isSing) {
                     System.out.println("订单不存在！");
                 }
                 break;
             case 4:
                 System.out.println("******删除订单******");
                 System.out.println("序号\t菜品名称\t价格\t点赞");//菜品信息
                 for (int j = 0; j < dishMeg.length; j++) {//点赞数
                     String likes = (like[j] == 0) ? "" : like[j] + "赞";
                     System.out.println((j + 1) + "\t" + dishMeg[j] +like[j]+"赞");
                 }
                 boolean isDelet = false;
                 System.out.println("请输入要删除的编号：");
                 int DeletNo = input.nextInt();
                 for (int i = 0; i < names.length; i++) {
                     if (names[i] != null && states[i] == 1 && i == (DeletNo - 1)) {
                         isDelet = true;

                         System.out.println("订单未签收成功！不能删除");

                     } else if (names[i] != null && states[i] == 1 && i == DeletNo - 1) {
                         isDelet = true;
                         //找订单位置的下标，在进行 删除，循环 移位，最后是置空
                         for (int j = i; j < names.length; j++) {
                             names[j] = names[j + 1];
                             dishMeg[j] = dishMeg[j + 1];
                             times[j] = times[j + 1];
                             adresses[j] = adresses[j + 1];
                             states[j] = states[j + 1];
                             sumPrices[j] = sumPrices[j + 1];
                         }
                         //最后一个元素置空
                         names[names.length - 1] = null;
                         dishMeg[names.length - 1] = null;
                         times[names.length - 1] = 0;
                         adresses[names.length - 1] = null;
                         states[names.length - 1] = 0;
                         sumPrices[names.length - 1] = 0;
                         System.out.println("您选择的订单已经完成删除！");
                     }
                     System.out.println("序号\t菜品名称\t价格\t点赞");//菜品信息
                     for (int j = 0; j < dishMeg.length; j++) {//点赞数
                         String likes = (like[j] == 0) ? "" : like[j] + "赞";
                         System.out.println((j + 1) + "\t" + dishMeg[j] +like[j]+"赞");
                     }
                 }
                 if (!isDelet) {
                     System.out.println("订单不存在！");
                 }

                 break;
             case 5:
                 System.out.println("******我要点赞******");
                 System.out.println("序号\t菜品名称\t价格\t点赞");//菜品信息
                 for (int j = 0; j < dishMeg.length; j++) {//点赞
                     String likes = (like[j] == 0) ? "" : like[j] + "赞";
                     System.out.println((j + 1) + "\t" + dishMeg[j] + "\t" + price[j] + "\t" + like);

                 }
                 System.out.println("请输入点赞的菜品编号：");
                 int likeNo = input.nextInt();
                 while (likeNo < 1 || likeNo > dishMeg.length) {
                     System.out.println("菜品编号错误，请重新输入：");
                     likeNo = input.nextInt();
                 }
                 //点赞数加1

                 like[likeNo - 1]++;
                 break;
             case 6:
                 System.out.println("******退出系统******");
                 System.exit(0);//退出系统
                 break;
         }
//         System.out.println("是否继续(y/n):");//判断退出系统
//         String isGo = input.next();
//         if ("n".equals(isGo)) ;
//         {
//             System.out.println("退出系统");
//             break;
//         }
//         break;
         System.out.println("请输入0返回：");
         num=input.nextInt();
     }

     while(num==0);
     System.out.println("谢谢使用，欢迎下次光临！");
    }
}
